package com.byfan.barter.service.Impl;

import com.byfan.barter.entity.User;
import com.byfan.barter.jpa.UserJpa;
import com.byfan.barter.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @Author: FBY
 * @Description
 * @Version 1.0
 * @Date: 2021/5/14 15:31
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserJpa userJpa;

    /**
     * 新增/修改用户
     * @param user
     * @return
     */
    @Override
    public User save(User user) {
        return userJpa.save(user);
    }

    /**
     * 根据用户openid获取用户信息
     * @param openid
     * @return
     */
    @Override
    public User getById(String openid) {
        Optional<User> optional = userJpa.findById(openid);
        if (optional.isPresent()){
            return optional.get();
        }
        return null;
    }
}
